package com.saxon.springboot.Controller;

import com.saxon.springboot.AsynService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class HelloWorld {

    AsynService asynService;

    @Autowired
    public void setAsynService (AsynService asynService) {
        this.asynService = asynService;
    }

    @RequestMapping ("/login")
    public static String login (@RequestParam ("name") String name, @RequestParam ("password") String password, Model model, HttpSession httpSession) {
        if (! StringUtils.isEmpty (name) && "123456".equals (password)) {
            httpSession.setAttribute ("user", "user");
            return "redirect:main.html";
        } else {
            model.addAttribute ("msg", "你输入的密码或者用户名有误");
            return "index";
        }
    }


    @GetMapping ("/hello")
    @ResponseBody
    public String hello () {
        System.out.println ("zzzz");
        asynService.Asyn ();
        return "OK";
    }
}
